package com.da.javatest.leetCode;

/**
 * @author chenlida
 * @date 2019/1/4 15:24
 * @description
 */
public class Code64 {
    public int minPathSum(int[][] grid) {
        if (grid == null) { return 0; }
        int l = grid.length;
        int h = grid[0].length;
        int[][] dp = new int[l][h];
        for (int i = 0; i < l; i++) {
            for (int j = 0; j < h; j++) {
                if (i == 0 && j == 0) {
                    dp[i][j] = grid[0][0];
                } else if (i == 0) {
                    dp[i][j] = dp[i][j - 1] + grid[i][j];
                } else if (j == 0) {
                    dp[i][j] = dp[i - 1][j] + grid[i][j];
                } else {
                    dp[i][j] = Math.min(dp[i - 1][j], dp[i][j - 1]) + grid[i][j];
                }
            }
        }
        return dp[l - 1][h - 1];
    }
}
